package com.jinmdz.fmis.mapper.mapper.provider;

import com.jinmdz.fmis.mapper.entity.SystemOperationLogEntity;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.jdbc.SQL;

/**
 * 系统操作日志表Provider
 *
 * @author generator
 * @date 2020-03-12 17:08
 */
public class SystemOperationLogProvider {

    /**
     * 增加SystemOperationLog
     *
     * @param entity 数据实体
     * @return String
     * @author generator
     * @date 2020-03-12 17:08
     */
    public String insertSystemOperationLog(@Param("entity") SystemOperationLogEntity entity) {
        return new SQL() {
            {
                INSERT_INTO(" system_operation_log ");

                if (entity.getDeleted() != null) {
                    VALUES(" deleted ", " #{entity.deleted,jdbcType=TINYINT} ");
                }

                VALUES(" operation_type_code ", " #{entity.operationTypeCode,jdbcType=SMALLINT} ");
                VALUES(" operation_type ", " #{entity.operationType,jdbcType=VARCHAR} ");
                VALUES(" business_code ", " #{entity.businessCode,jdbcType=VARCHAR} ");
                VALUES(" business_type_code ", " #{entity.businessTypeCode,jdbcType=SMALLINT} ");
                VALUES(" business_type ", " #{entity.businessType,jdbcType=VARCHAR} ");
                VALUES(" business_describe ", " #{entity.businessDescribe,jdbcType=VARCHAR} ");
                VALUES(" log_content ", " #{entity.logContent} ");
                VALUES(" log_describe ", " #{entity.logDescribe,jdbcType=VARCHAR} ");
                VALUES(" log_form ", " #{entity.logForm} ");
                VALUES(" old_value ", " #{entity.oldValue} ");
                VALUES(" new_value ", " #{entity.newValue} ");
                VALUES(" remark ", " #{entity.remark} ");
                VALUES(" create_user_name ", " #{entity.createUserName,jdbcType=VARCHAR} ");
                VALUES(" funeral_parlour_code ", " #{entity.funeralParlourCode,jdbcType=VARCHAR} ");
                VALUES(" create_user_id ", " #{entity.createUserId,jdbcType=INTEGER} ");

                if (entity.getUnmodified() != null) {
                    VALUES(" unmodified ", " #{entity.unmodified,jdbcType=TINYINT} ");
                }

                VALUES(" modified_user_id ", " #{entity.modifiedUserId,jdbcType=INTEGER} ");
                VALUES(" version ", " unix_timestamp(now()) ");
            }
        }.toString();
    }

    /**
     * 修改SystemOperationLog
     *
     * @param entity 数据实体
     * @return String
     * @author generator
     * @date 2020-03-12 17:08
     */
    public String updateSystemOperationLog(@Param("entity") SystemOperationLogEntity entity) {
        return new SQL() {
            {
                UPDATE(" system_operation_log ");

                if (entity.getDeleted() != null) {
                    SET(" deleted = #{entity.deleted,jdbcType=TINYINT} ");
                }

                SET(" operation_type_code = #{entity.operationTypeCode,jdbcType=SMALLINT} ");
                SET(" operation_type = #{entity.operationType,jdbcType=VARCHAR} ");
                SET(" business_code = #{entity.businessCode,jdbcType=VARCHAR} ");
                SET(" business_type_code = #{entity.businessTypeCode,jdbcType=SMALLINT} ");
                SET(" business_type = #{entity.businessType,jdbcType=VARCHAR} ");
                SET(" business_describe = #{entity.businessDescribe,jdbcType=VARCHAR} ");
                SET(" log_content = #{entity.logContent} ");
                SET(" log_describe = #{entity.logDescribe,jdbcType=VARCHAR} ");
                SET(" log_form = #{entity.logForm} ");
                SET(" old_value = #{entity.oldValue} ");
                SET(" new_value = #{entity.newValue} ");
                SET(" remark = #{entity.remark} ");
                SET(" create_user_name = #{entity.createUserName,jdbcType=VARCHAR} ");
                SET(" funeral_parlour_code = #{entity.funeralParlourCode,jdbcType=VARCHAR} ");

                if (entity.getUnmodified() != null) {
                    SET(" unmodified = #{entity.unmodified,jdbcType=TINYINT} ");
                }

                SET(" modified_user_id = #{entity.modifiedUserId,jdbcType=INTEGER} ");
                SET(" version = unix_timestamp(now()) ");
                WHERE(" id = #{entity.id,jdbcType=INTEGER} ");
                WHERE(" unmodified = 0 ");
                WHERE(" version = #{entity.version,jdbcType=INTEGER} ");
            }
        }.toString();
    }

    /**
     * 查询SystemOperationLog列表
     *
     * @param entity 数据实体
     * @return String
     * @author generator
     * @date 2020-03-12 17:08
     */
    public String listSystemOperationLog(@Param("entity") SystemOperationLogEntity entity) {
        return new SQL() {
            {
                StringBuilder builder = new StringBuilder();
                builder.append(" id,deleted,operation_type_code,operation_type,business_code,business_type_code,business_type,business_describe,log_content,log_describe,log_form,old_value,new_value,remark,create_user_name,funeral_parlour_code,create_user_id,gmt_create,unmodified,modified_user_id,gmt_modified,version ");
                SELECT(builder.toString());
                FROM(" system_operation_log ");

                if (entity.getOperationTypeCode() != null) {
                    WHERE(" operation_type_code = #{entity.operationTypeCode,jdbcType=SMALLINT} ");
                }

                if (entity.getOperationType() != null) {
                    WHERE(" operation_type = #{entity.operationType,jdbcType=VARCHAR} ");
                }

                if (entity.getBusinessCode() != null) {
                    WHERE(" business_code = #{entity.businessCode,jdbcType=VARCHAR} ");
                }

                if (entity.getBusinessTypeCode() != null) {
                    WHERE(" business_type_code = #{entity.businessTypeCode,jdbcType=SMALLINT} ");
                }

                if (entity.getBusinessType() != null) {
                    WHERE(" business_type = #{entity.businessType,jdbcType=VARCHAR} ");
                }

                if (entity.getBusinessDescribe() != null) {
                    WHERE(" business_describe = #{entity.businessDescribe,jdbcType=VARCHAR} ");
                }

                if (entity.getLogContent() != null) {
                    WHERE(" log_content = #{entity.logContent} ");
                }

                if (entity.getLogDescribe() != null) {
                    WHERE(" log_describe = #{entity.logDescribe,jdbcType=VARCHAR} ");
                }

                if (entity.getLogForm() != null) {
                    WHERE(" log_form = #{entity.logForm} ");
                }

                if (entity.getOldValue() != null) {
                    WHERE(" old_value = #{entity.oldValue} ");
                }

                if (entity.getNewValue() != null) {
                    WHERE(" new_value = #{entity.newValue} ");
                }

                if (entity.getRemark() != null) {
                    WHERE(" remark = #{entity.remark} ");
                }

                if (entity.getCreateUserName() != null) {
                    WHERE(" create_user_name = #{entity.createUserName,jdbcType=VARCHAR} ");
                }

                if (entity.getFuneralParlourCode() != null) {
                    WHERE(" funeral_parlour_code = #{entity.funeralParlourCode,jdbcType=VARCHAR} ");
                }

            }
        }.toString();
    }
}